load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "go_path", "nogo")
load("//build/bazelutil/staticcheckanalyzers:def.bzl", "STATICCHECK_CHECKS")

# Consider using `dev` to easily perform Bazel builds. Run `dev doctor` to see
# if your machine is up to snuff, and `dev -h` for a list of everything `dev`
# can do.

exports_files([
    "DEPS.bzl",
    "TEAMS.yaml",
    "WORKSPACE",
    "go.mod",
    "go.sum",
])

# The following directives inform gazelle how to auto-generate BUILD.bazel
# files throughout the repo. By including them here, we can run gazelle using
# `bazel run //:gazelle` instead of invoking gazelle directly.
#
# NB: Be sure to re-generate BUILD.bazel files if any of the directives below
# are changed.

# Define the gazelle prefix and what the autogenerated BUILD files should be
# named as.
#
# gazelle:prefix github.com/cockroachdb/cockroach
# gazelle:build_file_name BUILD.bazel
# gazelle:build_tags bazel,compose,deadlock,fast_int_set_small,fast_int_set_large,gss,slow

# Enable protobuf generation.
#
# gazelle:proto default
# gazelle:proto_group go_package
# gazelle:go_proto_compilers //pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler
# gazelle:go_grpc_compilers //pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_grpc_compiler

# Gazelle needs the following resolve hints.
#
# gazelle:resolve go github.com/grpc-ecosystem/grpc-gateway/runtime @com_github_grpc_ecosystem_grpc_gateway//runtime:go_default_library
# gazelle:resolve go github.com/grpc-ecosystem/grpc-gateway/utilities @com_github_grpc_ecosystem_grpc_gateway//utilities:go_default_library
# gazelle:resolve go github.com/grpc-ecosystem/grpc-gateway/internal @com_github_grpc_ecosystem_grpc_gateway//internal
# gazelle:resolve proto proto errorspb/errors.proto @com_github_cockroachdb_errors//errorspb:errorspb_proto
# gazelle:resolve proto go errorspb/errors.proto @com_github_cockroachdb_errors//errorspb
# gazelle:resolve proto proto gogoproto/gogo.proto @com_github_gogo_protobuf//gogoproto:gogo_proto
# gazelle:resolve proto go gogoproto/gogo.proto @com_github_gogo_protobuf//gogoproto
# gazelle:resolve proto proto google/api/annotations.proto @go_googleapis//google/api:annotations_proto
# gazelle:resolve proto go google/api/annotations.proto @org_golang_google_genproto//googleapis/api/annotations:go_default_library
# gazelle:resolve proto io/prometheus/client/metrics.proto @com_github_prometheus_client_model//io/prometheus/client:io_prometheus_client_proto
# gazelle:resolve proto go io/prometheus/client/metrics.proto @com_github_prometheus_client_model//go
# gazelle:resolve go github.com/prometheus/client_model/go @com_github_prometheus_client_model//go
# gazelle:resolve go github.com/cockroachdb/cockroach/pkg/ccl/gssapiccl //pkg/ccl/gssapiccl
# gazelle:resolve go github.com/cockroachdb/cockroach/pkg/cli_test //pkg/cli:cli_test
# gazelle:resolve go github.com/cockroachdb/cockroach/pkg/sql/colflow_test //pkg/sql/colflow:colflow_test
# gazelle:resolve go github.com/cockroachdb/cockroach/pkg/util/caller_test //pkg/util/caller:caller_test
# gazelle:resolve go github.com/cockroachdb/cockroach/pkg/util/json_test //pkg/util/json:json_test
# gazelle:resolve go google.golang.org/genproto/googleapis/pubsub/v1 @org_golang_google_genproto//googleapis/pubsub/v1:pubsub
# gazelle:resolve go google.golang.org/genproto/googleapis/cloud/kms/v1 @org_golang_google_genproto//googleapis/cloud/kms/v1:kms
# gazelle:resolve go google.golang.org/genproto/googleapis/devtools/build/v1 @org_golang_google_genproto//googleapis/devtools/build/v1:build

# See pkg/kv/kvpb/gen/BUILD.bazel for more details.
#
# gazelle:resolve proto go kv/kvpb/api.proto //pkg/kv/kvpb
# gazelle:resolve proto go kv/kvpb/errors.proto //pkg/kv/kvpb
# gazelle:resolve proto go roachpb/data.proto //pkg/roachpb
# gazelle:resolve proto go roachpb/index_usage_stats.proto //pkg/roachpb
# gazelle:resolve proto go roachpb/internal.proto //pkg/roachpb
# gazelle:resolve proto go roachpb/internal_raft.proto //pkg/roachpb
# gazelle:resolve proto go roachpb/io-formats.proto //pkg/roachpb
# gazelle:resolve proto go roachpb/metadata.proto //pkg/roachpb
# gazelle:resolve proto go roachpb/span_config.proto //pkg/roachpb
# gazelle:exclude pkg/kv/kvpb/batch_generated.go

# See pkg/sql/opt/optgen/cmd/langgen/BUILD.bazel for more details.
#
# gazelle:resolve go github.com/cockroachdb/cockroach/pkg/sql/opt/optgen/lang //pkg/sql/opt/optgen/lang

# We exclude a few things from gazelle consideration:
# - The protobuf C dependency, it's are already bazel-ified, lest we overwrite
#   those build files.
# - The artifacts directory.
# - Most checked-in autogenerated files (they'll get autogenerated on the fly
#   through bazel). These include stringer files, eg.go files, etc.
# - testdata packages that looks like go packages, but aren't
#   (testdata/src/example.com).
# - A few auto-generated sql parser files.
# - The vendor directory. We're using external targets for go dependencies,
#   generated without actually looking at vendor. See #58229.
#
# gazelle:exclude _bazel
# gazelle:exclude c-deps/krb5
# gazelle:exclude artifacts
# gazelle:exclude bin
# gazelle:exclude build/builder_home
# gazelle:exclude lib
# gazelle:exclude pkg/ccl/gssapiccl
# gazelle:exclude pkg/ui/node_modules
# gazelle:exclude pkg/ui/workspaces/cluster-ui/node_modules
# gazelle:exclude pkg/ui/workspaces/db-console/node_modules
# gazelle:exclude pkg/ui/workspaces/db-console/src/js/node_modules
# gazelle:exclude pkg/ui/workspaces/e2e-tests/node_modules
# gazelle:exclude pkg/ui/workspaces/eslint-plugin-crdb/node_modules
# gazelle:exclude pkg/ui/workspaces/crdb-api-client/node_modules
# gazelle:exclude vendor
# gazelle:exclude .vendor.tmp.*
# gazelle:exclude **/zcgo_flags.go
# gazelle:exclude **/zcgo_flags_*.go
# gazelle:exclude **/*.og.go
# gazelle:exclude **/*.eg.go
# gazelle:exclude **/*.pb.go
# gazelle:exclude **/*.pb.gw.go
# gazelle:exclude **/*_interval_btree.go
# gazelle:exclude **/*_interval_btree_test.go
# gazelle:exclude **/*_generated.go
# gazelle:exclude **/*_generated_test.go
# gazelle:exclude pkg/sql/parser/sql.go
# gazelle:exclude pkg/sql/parser/helpmap_test.go
# gazelle:exclude pkg/sql/parser/help_messages.go
# gazelle:exclude pkg/sql/lexbase/keywords.go
# gazelle:exclude pkg/sql/lexbase/tokens.go
# gazelle:exclude pkg/sql/lexbase/reserved_keywords.go
# gazelle:exclude pkg/sql/plpgsql/parser/lexbase/keywords.go
# gazelle:exclude pkg/sql/plpgsql/parser/lexbase/tokens.go
# gazelle:exclude pkg/sql/plpgsql/parser/lexbase/reserved_keywords.go
# gazelle:exclude pkg/sql/scanner/token_names_test.go
# gazelle:exclude pkg/sql/schemachanger/scexec/mocks_generated_test.go
# gazelle:exclude pkg/cmd/prereqs/testdata
# gazelle:exclude pkg/testutils/**/testdata/**
# gazelle:exclude pkg/security/securitytest/embedded.go
# gazelle:exclude pkg/roachprod/vm/aws/embedded.go
# gazelle:exclude pkg/**/*_string.go
# gazelle:exclude pkg/ui/distccl/distccl_no_bazel.go
# gazelle:exclude pkg/ui/distoss/distoss_no_bazel.go
# gazelle:exclude pkg/util/buildutil/crdb_test_off.go
# gazelle:exclude pkg/util/buildutil/crdb_test_on.go
# gazelle:exclude pkg/testutils/bazelcodecover/crdb_test_off.go
# gazelle:exclude pkg/testutils/bazelcodecover/crdb_test_on.go
# gazelle:exclude pkg/acceptance/compose/gss/psql/*
# gazelle:exclude pkg/acceptance/test_main.go
#
# Generally useful references:
#
#   https://docs.bazel.build/versions/master/user-manual.html
#   https://docs.bazel.build/versions/master/guide.html

gazelle(
    name = "gazelle",
    prefix = "github.com/cockroachdb/cockroach",
)

nogo(
    name = "crdb_nogo",
    config = "//build/bazelutil:nogo_config.json",
    visibility = ["//visibility:public"],
    deps = select({
        "//build/toolchains:nogo": [
            "@org_golang_x_tools//go/analysis/passes/asmdecl:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/assign:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/atomic:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/atomicalign:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/bools:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/buildssa:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/buildtag:go_default_library",
            # TODO(rules_go#2396): pass raw cgo sources to cgocall and re-enable.
            # "@org_golang_x_tools//go/analysis/passes/cgocall:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/composite:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/copylock:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/ctrlflow:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/deepequalerrors:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/errorsas:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/findcall:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/httpresponse:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/ifaceassert:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/inspect:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/lostcancel:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/nilfunc:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/nilness:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/pkgfact:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/printf:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/shift:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/sortslice:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/stdmethods:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/stringintconv:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/structtag:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/testinggoroutine:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/tests:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/unmarshal:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/unreachable:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/unsafeptr:go_default_library",
            "@org_golang_x_tools//go/analysis/passes/unusedresult:go_default_library",
            "//pkg/testutils/lint/passes/deferunlockcheck",
            "//pkg/testutils/lint/passes/descriptormarshal",
            "//pkg/testutils/lint/passes/errcheck",
            "//pkg/testutils/lint/passes/errcmp",
            "//pkg/testutils/lint/passes/errwrap",
            "//pkg/testutils/lint/passes/fmtsafe",
            "//pkg/testutils/lint/passes/grpcclientconnclose",
            "//pkg/testutils/lint/passes/grpcstatuswithdetails",
            "//pkg/testutils/lint/passes/hash",
            "//pkg/testutils/lint/passes/leaktestcall",
            "//pkg/testutils/lint/passes/nilness",
            "//pkg/testutils/lint/passes/nocopy",
            "//pkg/testutils/lint/passes/redactcheck",
            "//pkg/testutils/lint/passes/returncheck",
            "//pkg/testutils/lint/passes/returnerrcheck",
            "//pkg/testutils/lint/passes/shadow",
            "//pkg/testutils/lint/passes/timer",
            "//pkg/testutils/lint/passes/unconvert",
        ] + STATICCHECK_CHECKS,
        "//conditions:default": [],
    }),
)
